﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

/// <summary>
/// InpatientsOperation 的摘要说明
/// 主要是病人的一些操作
/// </summary>
public class InpatientsOperation
{
    private Dbcom cm;
    public InpatientsOperation(Dbcom CM)
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
        cm = CM;
    }

    /// <summary>
    /// 根据医生姓名查询病人信息
    /// </summary>
    /// <param name="DoctorName">医生id</param>
    /// <returns></returns>
    public DataSet GetInptientByDoctorCode(string sick_doctor_name)
    {
        try
        {
            //string sql = "select p1.id as 主键,p1.patient_name 病人姓名,p1.birthday as 出生日期,p1.home_address 家庭住址,"+
            //             "p1.gender_code,p1.marriage_state,p1.sick_bed_no,p1.sick_doctor_id,p1.sick_doctor_name," +
            //             "p1.section_name,p1.sick_area_name,p1.die_time from t_in_patient p1 where sick_doctor_name='" +
            //             sick_doctor_name + "'";
            string sql = "select p1.id as 主键,p1.patient_name 病人姓名,p1.birthday as 出生日期,p1.home_address 家庭住址," +
                        "(case when p1.gender_code=0 then '男' else '女' end) as 性别,p1.marriage_state as 婚姻状况,p1.sick_bed_no as 床位,p1.sick_doctor_id,p1.sick_doctor_name as 管床医生," +
                        "p1.section_name as 科室,p1.sick_area_name  as 病区,p1.in_time as 入院时间,p1.die_time as 出院日期 from t_in_patient p1 "+
                        "where p1.id in (select b.patient_id from t_patients_doc b inner join t_patient_doc_colb b2 on b.tid=b2.tid ) and p1.sick_doctor_id="+ sick_doctor_name + "";          
            return Dbcom.GetDataSet(sql);
        }
        catch
        {
            return null;
        }
    }

    /// <summary>
    /// 根据医生姓名查询病人信息
    /// </summary>
    /// <param name="DoctorName">医生id</param>
    /// <returns></returns>
    public DataSet GetInptientBySectionCode(string section_id)
    {
        try
        {
            //string sql = "select p1.id as 主键,p1.patient_name 姓名,p1.birthday as 出生日期,p1.home_address 家庭住址," +
            //            "(case when p1.gender_code=0 then '男' else '女' end) as 性别,p1.marriage_state as 婚姻状况,p1.sick_bed_no as 床位,p1.sick_doctor_id,p1.sick_doctor_name as 管床医生," +
            //            "p1.section_name as 科室,p1.sick_area_name  as 病区,p1.in_time as 入院时间,p1.die_time as 出院日期 from t_in_patient p1 " +
            //            "where p1.section_id=" + section_id + " order by id desc ";

            //慢阻肺
            string sql = "select rownum as 序号,p1.patient_name 姓名,p1.id as 档案号,"+
                        "p1.document_time as 建档日期,(case when p1.gender_code=0 then '男' else '女' end) as 性别,"+
                        "p1.agestr as 年龄,p1.card_id as 身份证号,p1.home_phone as 电话号码,'慢阻肺' as 诊断结论,"+
                        "'稳定性高风险' as 管理登记,p1.sick_doctor_name as 负责医生,'6' as 随访次数,"+
                        "'2017-05-09' as 最近随访,'门诊随访' as 随访类型,p1.sick_doctor_id,p1.id from t_in_patient p1"+
                        " where p1.section_id = 2 order by id desc ";


           
            return Dbcom.GetDataSet(sql);
        }
        catch
        {
            return null;
        }
    }

    /// <summary>
    /// 根据医生姓名查询病人信息
    /// </summary>
    /// <param name="DoctorName">医生id</param>
    /// <returns></returns>                                                                                                          
    public DataSet GetInptientByStr(string patient_name,string section)
    {
        try
        {
            //string sql = "select p1.id,p1.patient_name,p1.birthday,p1.home_address," +
            //             "p1.gender_code,p1.marriage_state,p1.sick_bed_no,p1.sick_doctor_id,p1.sick_doctor_name," +
            //             "p1.section_name,p1.sick_area_name,p1.die_time from t_in_patient p1 where patient_name like '%" +
            //             patient_name + "%' and section_name like '%"+ section + "%'";

            string sql = "select rownum as 序号,p1.patient_name 姓名,p1.id as 档案号,p1.in_time as 建档日期,(case when p1.gender_code=0 then '男' else '女' end) as 性别,p1.agestr as 年龄,p1.card_id as 身份证号," +
                        "p1.home_phone as 电话号码,p1.diagnosisresult as 诊断结论,'稳定性高风险' as 管理登记,p1.sick_doctor_name as 负责医生,'6' as 随访次数,'2017-05-09' as 最近随访,'门诊随访' as 随访类型," +
                        "p1.sick_doctor_id,p1.id from t_in_patient p1 where patient_name like '%" + patient_name + "%' order by id desc ";


            return Dbcom.GetDataSet(sql);
        }
        catch
        {
            return null;
        }
    }


    /// <summary>
    /// 初始化病人信息
    /// </summary>
    /// <param name="row">当前行</param>
    /// <returns>病人对象</returns>
    public InPatientInfo InitPatient(string patientid)
    {
        if (patientid != "")
        {
            DataRow row = Dbcom.GetDataSet("select * from t_in_patient where id=" + patientid + "").Tables[0].Rows[0];
            InPatientInfo inpatient = new InPatientInfo(0, "", "", "", "", "", "", "", "", "");
            try
            {

                DataRow[] codesrows = null;
                //婚姻
                codesrows = Dbcom.DS_CODE.Tables[0].Select("type='132' and code='" + row["Marriage_State"].ToString() + "'");
                if (codesrows.Length > 0)
                    inpatient.Marrige_State = codesrows[0]["name"].ToString();
                else
                    inpatient.Marrige_State = row["Marriage_State"].ToString();               
                if (Dbcom.DS_AREA != null)
                {
                    if (row["native_place"].ToString() != "")
                    {
                        inpatient.Natiye_place = row["native_place"].ToString();
                    }
                    else
                    {
                        inpatient.Natiye_place = "";
                    }
                }

                //民族             
                inpatient.Folk_code = row["Folk_Code"].ToString();
                //职业             
                inpatient.Career = row["Career"].ToString();
                inpatient.Health_card_no= row["health_card_no"].ToString();
                inpatient.Career_other = row["career_other"].ToString();
                inpatient.Pay_Manager = row["Pay_Manner"].ToString();
                inpatient.Now_address = row["now_address"].ToString();
                inpatient.Now_addres_phone = row["now_addres_phone"].ToString();
                inpatient.Now_addres_postno = row["now_addres_postno"].ToString();
                inpatient.Country = row["country"].ToString();
                inpatient.Medicare_no = row["Medicare_NO"].ToString();
                inpatient.Home_address = row["Home_Address"].ToString();
                inpatient.HomePostal_code = row["Homepostal_Code"].ToString();
                inpatient.Home_phone = row["Home_Phone"].ToString();
                inpatient.Office = row["Office"].ToString();
                inpatient.Office_address = row["Office_Address"].ToString();
                inpatient.Office_phone = row["Office_Phone"].ToString();
                inpatient.Relation = row["Relation"].ToString();
                inpatient.Relation_name = row["Relation_Name"].ToString();
                inpatient.Relation_address = row["Relation_Address"].ToString();
                inpatient.Relation_phone = row["Relation_Phone"].ToString();
                inpatient.RelationPos_code = row["RelationPOS_Code"].ToString();
                inpatient.OfficePos_code = row["OfficePOS_Code"].ToString();
                if (row["InHospital_Count"].ToString() != "")
                    inpatient.InHospital_count = Convert.ToInt32(row["InHospital_Count"].ToString());
                inpatient.Cert_Id = row["CERT_ID"].ToString();
                inpatient.Out_Id = row["out_id"].ToString();
                inpatient.In_Circs = row["IN_Circs"].ToString();
                inpatient.Birth_place = row["Birth_Place"].ToString();
                inpatient.Id = Int32.Parse(row["id"].ToString());
                inpatient.Patient_Name = row["patient_name"].ToString();
                inpatient.Gender_Code = row["gender_code"].ToString();
                inpatient.Birthday = row["birthday"].ToString();
                inpatient.PId = row["pid"].ToString();
                if (row["insection_id"].ToString() != "")
                    inpatient.Insection_Id = Convert.ToInt32(row["insection_id"]);
                inpatient.Insection_Name = row["insection_name"].ToString();
                inpatient.In_Area_Id = Convert.ToInt32(row["in_area_id"]);
                inpatient.In_Area_Name = row["in_area_name"].ToString();               
                inpatient.Age = row["age"].ToString();                  
                inpatient.Age_unit = row["age_unit"].ToString();                             
                inpatient.Child_age = row["child_age"].ToString();             
                //inpatient.Action_State = row["action_state"].ToString();
                inpatient.Sick_Doctor_Id = row["sick_doctor_id"].ToString();
                inpatient.Sick_Doctor_Name = row["sick_doctor_name"].ToString();
                if (row["sick_area_id"].ToString() != "")
                    inpatient.Sike_Area_Id = Int32.Parse(row["sick_area_id"].ToString());
                inpatient.Sick_Area_Name = row["sick_area_name"].ToString();
                if (row["section_id"].ToString() != "")
                    inpatient.Section_Id = Int32.Parse(row["section_id"].ToString());
                inpatient.Section_Name = row["section_name"].ToString();
                if (row["in_time"] != null)
                    inpatient.In_Time = DateTime.Parse(row["in_time"].ToString());
                inpatient.State = row["state"].ToString();
                if (row["sick_bed_id"].ToString() != "")
                    inpatient.Sick_Bed_Id = Int32.Parse(row["sick_bed_id"].ToString());
                inpatient.Sick_Bed_Name = row["sick_bed_no"].ToString();
                inpatient.Sick_Degree = Convert.ToString(row["Sick_Degree"]);
                inpatient.Nurse_Level = Convert.ToString(row["Nurse_Level"]);
                if (row["Die_flag"].ToString() != "")
                    inpatient.Die_flag = Convert.ToInt32(row["Die_flag"]);
                if (row["die_time"].ToString() != "")
                {
                    inpatient.Die_time = Convert.ToDateTime(row["die_time"]);
                }
                if (row["Sick_Group_Id"].ToString() != "")
                    inpatient.Sick_Group_Id = Convert.ToInt32(row["Sick_Group_Id"]);
                inpatient.Card_Id = row["card_id"].ToString();

                inpatient.Patient_Id = row["patient_Id"].ToString();
                if (row["PROPERTY_FLAG"] != null)
                    inpatient.Property_flag = row["PROPERTY_FLAG"].ToString();
                if (row["CAREER_OTHER"] != null)
                    inpatient.Property_flag = row["CAREER_OTHER"].ToString();
                inpatient.Sick_doc_no = row["SICK_DOC_NO"].ToString();

                inpatient.His_id = row["his_id"].ToString();
                inpatient.In_Approach= row["in_approach"].ToString();

                //袁杨添加  责任护士 151125 
                if (row["zrhs"].ToString() != "")
                {
                    inpatient.ZRHS = row["zrhs"].ToString();
                }
                if (row["zrhsname"].ToString() != "")
                {
                    inpatient.ZRHSNAME = row["zrhsname"].ToString();
                }
                if (row["exe_document_time"] != null)
                {
                    inpatient.Exe_document_time = row["exe_document_time"].ToString();
                }
                if (row["document_state"] != null)
                    inpatient.Document_State = row["document_state"].ToString();
            }
            catch (System.Exception ex)
            {

            }
            return inpatient;
        }
        else
        {
            return null;
        }
    }   


    /// 通过生日和当前日期计算岁，月，天
    /// </summary>
    /// <param name="birthday">生日</param>
    /// <param name="now">当前日期</param>
    /// <param name="year">岁</param>
    /// <param name="month">月</param>
    /// <param name="day">天</param>
    public void GetAgeByBirthday(DateTime birthday, DateTime now, ref int year, ref int month, ref int day)
    {
        //int day, month, year;
        //生日的年，月，日
        int birthdayYear = birthday.Year;
        int birthdayMonth = birthday.Month;
        int birthdayDay = birthday.Day;

        //当前时间的年,月,日
        int nowYear = now.Year;
        int nowMonth = now.Month;
        int nowDay = now.Day;

        //得到天
        if (nowDay >= birthdayDay)
        {
            day = nowDay - birthdayDay;
        }
        else
        {
            nowMonth -= 1;
            day = GetDay(nowMonth, nowYear) + nowDay - birthdayDay;
        }
        //得到月
        if (nowMonth >= birthdayMonth)
        {
            month = nowMonth - birthdayMonth;
        }
        else
        {
            nowYear -= 1;
            month = 12 + nowMonth - birthdayMonth;
        }
        //得到年
        year = nowYear - birthdayYear;
    }


    /// <summary>
    /// 病人入区科室
    /// </summary>
    /// <param name="dtpBirthday"></param>
    /// <param name="dtpDatetime"></param>
    /// <param name="cboGender"></param>
    /// <param name="txtNumber"></param>
    /// <param name="cboAgeunit"></param>
    /// <param name="txtAge"></param>
    /// <param name="txtName"></param>
    /// <param name="txtPiyin"></param>
    /// <param name="cboCusectionSelectedValue"></param>
    /// <param name="cboCusectionText"></param>
    /// <param name="cboCusickSelectedValue"></param>
    /// <param name="cboCusickText"></param>
    /// <param name="cbxDoctor"></param>
    /// <param name="cbxBed_IdSelectedValue"></param>
    /// <param name="cbxBed_IdText"></param>
    /// <param name="cbxDoctorText"></param>
    /// <param name="cbxDoctorSelectedValue"></param>
    /// <param name="dtpInAreaTime"></param>
    /// <param name="Account_id"></param>
    /// <returns></returns>
    public int PatientInSectionsArea(InPatientInfo inpo,string Account_id)
    {
        if (inpo.Id == 0)
        {
            //添加操作
            string sql = "";
            string inpatientID = Dbcom.GenId().ToString();//自动生成病人ID
            string sqlstr = "select a.id from t_in_patient a inner join t_inhospital_action b on a.id=b.patient_id where a.patient_name='" + inpo.Patient_Name + "' and a.pid='" + inpo.PId + "'";
            DataSet dsPatient = Dbcom.GetDataSet(sqlstr);
            if (dsPatient != null)
            {
                if (dsPatient.Tables[0].Rows.Count > 0)
                {
                    //App.MsgWaring("已经存在了相同的病人！");
                    return -1;
                }
            }
            inpo.Id = Convert.ToInt32(inpatientID);
            if (isExisitNames(inpo.PId, inpo.Patient_Name))
            {
                //App.Msg("已经存在了相同名称的病人住院号了！");
                // txtNumber.Focus();
                return -2;
            }
            string id = Dbcom.GenId().ToString();       //得到当前异动表里面的最大id加1.
            //向病人表中添加一个新病人
            sql = "insert into T_IN_PATIENT(ID,PATIENT_NAME,NAME_PINYIN,GENDER_CODE," +
                "BIRTHDAY,PID,AGE,AGE_UNIT,SECTION_ID,SECTION_NAME," +
                "INSECTION_ID,INSECTION_NAME,IN_AREA_ID,IN_AREA_NAME," +
                "SICK_AREA_ID,SICK_AREA_NAME,IN_TIME,CHILD_AGE," +
                "pay_manner,Country,folk_code,marriage_state,career,CAREER_OTHER,birth_place," +
                "native_place,now_address,Now_addres_phone,Now_addres_PostNo,home_address,"+
                "homepostal_code,office_address,officepos_code,office_phone,relation_address,"+
                "relation_name,relation,relation_phone,IN_Approach) values('"
                 + inpatientID + "','"
                 + inpo.Patient_Name + "','"
                 + inpo.Name_Pinyin + "','"
                 + inpo.Gender_Code + "',to_timestamp('"
                 + inpo.Birthday + "','syyyy-mm-dd '),'"
                 + inpo.PId + "','"
                 + inpo.Age + "','岁','"
                 + inpo.Section_Id + "','"
                 + inpo.Section_Name + "','"
                 + inpo.Insection_Id + "','"
                 + inpo.Insection_Name + "','"  
                 + inpo.In_Area_Id + "','"
                 + inpo.In_Area_Name + "','"
                 + inpo.Sike_Area_Id + "','"
                 + inpo.Sick_Area_Name + "',to_timestamp('"
                 + inpo.In_Time + "','syyyy-mm-dd hh24:mi:ss.ff9'),'" 
                 + inpo.Child_age + "','"+ inpo.Pre_Pay+ "','"+ inpo.Country+ "','"+ inpo.Folk_code+ "','"
                 +inpo.Marrige_State+"','"+inpo.Career+"','"+inpo.Career_other+"','"+inpo.Birth_place+"','"
                 +inpo.Natiye_place+"','"+inpo.Now_address+"','"+inpo.Now_addres_phone+"','"+inpo.Now_addres_postno+"','"
                 +inpo.Home_address+"','"+inpo.HomePostal_code+"','"+
                 inpo.Office_address+"','"+inpo.OfficePos_code+"','"+inpo.Office_phone+"','"
                 +inpo.Relation_address+"','"+inpo.Relation_name+"','"+inpo.Relation+"','"
                 +inpo.Relation_phone+"','"+inpo.In_Approach+"')";

            //指定床号后，该床的状态改为占有74
            string UpdateBed_State = "update t_sickbedinfo set state=74,sid=" + inpo.Section_Id + ",pid=" + inpatientID + ",patient_id=" + inpatientID + " where bed_id=" + inpo.Sick_Bed_Id + "";

            //向异动表插入一条入区记录
            string InsertInArea = "insert into t_inhospital_action (id,sid,said,pid,action_type," +
                                    " action_state,happen_time,bed_id,doctor_id,operate_id,next_id,preview_id,patient_id)" +
                                    " values(" + id + "," + inpo.Section_Id + "," + inpo.Sike_Area_Id + ",'" + inpatientID + "'," +
                                    "'入区','4',sysdate," + inpo.Sick_Bed_Id + ",'" + inpo.Sick_Doctor_Id + "'," + Account_id + ",0,0," + inpatientID + ")";
            //向质控临时表新增一条入区记录
            string InsertJob_Temp = "insert into v_job_temp(pid,operate_type,operate_time,patient_id)" +
                                    " values('" + inpatientID + "','入区',to_timestamp('" + inpo.In_Time
                                    + "','yyyy-MM-dd hh24:mi:ss')," + inpatientID + ")";
            string[] arr = new string[4];
            arr[0] = sql;
            arr[1] = UpdateBed_State;
            arr[2] = InsertInArea;
            arr[3] = InsertJob_Temp;
            int count = Dbcom.ExecuteBatch(arr);
            return count;
        }
        else
        {
            //修改操作
            string sql = "update t_in_patient set in_doctor_id='" + inpo.In_Doctor_Id + "'," +
                                              " in_doctor_name='" + inpo.In_Doctor_Name + "',sick_doctor_id='" + inpo.Sick_Doctor_Id + "'," +
                                              " sick_doctor_name='" + inpo.Sick_Doctor_Name + "',in_bed_id=" + inpo.In_Bed_Id + "," +
                                              " in_bed_no='" + inpo.In_Bed_Name + "',sick_bed_id=" + inpo.Sick_Bed_Id + ",sick_bed_no='" +inpo.Sick_Bed_Name + "'," +
                                              " in_time=to_timestamp('" + inpo.In_Time + "','yyyy-MM-dd hh24:mi:ss')," +
                                              " section_id=" + inpo.Section_Id + "," +
                                              " section_name='" + inpo.Section_Name + "',insection_id=" + inpo.Insection_Id + "," +
                                              " insection_name='" + inpo.Insection_Name + "'," +                                             
                                              " pay_manner='" + inpo.Pay_Manager + "'," +
                                              " Country='" + inpo.Country + "'," +
                                              " folk_code='" + inpo.Folk_code + "'," +
                                              " marriage_state='" + inpo.Marrige_State + "'," +
                                              " career='" + inpo.Career + "'," +
                                              " CAREER_OTHER='" + inpo.Career_other + "'," +
                                              " birth_place='" + inpo.Birth_place + "'," +
                                              " native_place='" + inpo.Natiye_place + "'," +
                                              " now_address='" + inpo.Now_address + "'," +
                                              " Now_addres_phone='" + inpo.Now_addres_phone + "'," +
                                              " Now_addres_PostNo='" + inpo.Now_addres_postno+ "'," +
                                              " home_address='" + inpo.Home_address + "'," +
                                              " homepostal_code='" + inpo.HomePostal_code + "'," +
                                              " office_address='" + inpo.Office_address + "'," +
                                              " officepos_code='" + inpo.OfficePos_code + "'," +
                                              " office_phone='" + inpo.Office_phone + "'," +
                                              " relation_address='" + inpo.Relation_address + "'," +  
                                              " relation_name='" + inpo.Relation_name + "'," +
                                              " relation='" + inpo.Relation + "'," +
                                              " relation_phone='" + inpo.Relation_phone + "'," +
                                              " IN_Approach='" + inpo.In_Approach + "'," +
                                              " health_card_no='"+ inpo.Health_card_no+ "'," +
                                              " card_id='"+inpo.Card_Id+"' "+
                                              " where id=" + inpo.Id + "";          
            int count = Dbcom.ExecuteSQL(sql);
            return count;
        }
                        
    }


    /// <summary>
    /// 查询指定科室
    /// </summary>
    /// <param name="sid"></param>
    /// <returns></returns>
    public DataSet GetSection(string sid,string said)
    {
        string sql = "" ;
        if (sid == "")
        {
            sql = "select aa.sid,aa.section_name from t_sectioninfo aa inner join t_section_area bb on aa.sid = bb.sid where bb.said = " + said;
        }
        else
        {
            sql = "select sid,section_name from t_sectioninfo where sid=" + sid;
        }
        DataSet ds = Dbcom.GetDataSet(sql);
        return ds;
    }

    /// <summary>
    /// 查询指定科室
    /// </summary>
    /// <param name="sid"></param>
    /// <returns></returns>
    public DataSet GetSickArea(string sid,string said)
    {
        string sql = "select said,sick_area_name from t_sickareainfo where said = " + said;
        if (said == "")
        {
            sql = "select aa.said,aa.sick_area_name from t_sickareainfo aa inner join t_section_area bb on aa.said = bb.said where bb.sid = " + sid;
        }
        else
        {
            sql = "select said,sick_area_name from t_sickareainfo where said= " + said;
        }
        DataSet ds = Dbcom.GetDataSet(sql);
        return ds;
    }

    /// <summary>
    /// 根据病区获取相关的床位
    /// </summary>
    /// <param name="sickareaId"></param>
    /// <returns></returns>
    public DataSet GetEmptyBed(string sid,string said)
    {

        //if (sid != "")
        //{
        //    //由于App.UserAccount得不到病区ID，使用科室ID在t_section_area表中得到病区ID
        //    string sql_getSickareaId = "select said from t_section_area where sid=" + sid;
        //    DataSet ds1 = Dbcom.GetDataSet(sql_getSickareaId);
        //    DataTable dt1 = ds1.Tables[0];
        //    DataRow row = dt1.Rows[0];
        //    said = row["said"].ToString();
        //}        


        string Select_All_Bed = "select a.bed_id,a.bed_no from t_sickbedinfo a" +
                                " left join t_sickroominfo b on a.srid = b.srid" +
                                " left join t_sickareainfo c on b.said = c.said" +
                                " where a.enableflag='Y' and a.said=" + said + " order by bed_no asc";                          //查找所属科室病区所有空闲的病床

        if (sid != "")
        {
            Select_All_Bed = "select a.bed_id,a.bed_no from t_sickbedinfo a" +                             
                             " where a.enableflag='Y' and a.sid=" + sid + " order by bed_no asc";                          //查找所属科室病区所有空闲的病床

        }
        return Dbcom.GetDataSet(Select_All_Bed);

    }

    /// <summary>
    /// 根据科室或相关的科室医生
    /// </summary>
    /// <param name="section_id"></param>
    /// <returns></returns>
    public DataSet GetDoctor(string section_id)
    {
        //获取当前用户所在科室的医生            
        string Sql = "select distinct(a.user_id),a.user_name from t_userinfo a" +
                     " inner join t_account_user b on a.user_id=b.user_id" +
                     " inner join t_account c on b.account_id = c.account_id" +
                     " inner join t_acc_role d on d.account_id = c.account_id" +
                     " inner join t_role e on e.role_id = d.role_id" +
                     " inner join t_acc_role_range f on d.id = f.acc_role_id" +
                     " where f.section_id='" + section_id + "' and  e.role_type='D'";
        return Dbcom.GetDataSet(Sql);
        
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public int Test2(int t1,int t2)
    {
       return  Dbcom.ExecuteSQL("insert into t_test(t1,t2)values('"+t1.ToString()+"','"+t2.ToString()+"')");
    }

    public DataSet GetTextTest()
    {
        return Dbcom.GetDataSet("select * from t_text");
    }

    /// <summary>
    /// 判断是否出现重名ID
    /// </summary>
    /// <param Name="Id"></param>
    /// <returns></returns>
    private bool isExisitNames(string id,string txtName)
    {
        DataSet ds = Dbcom.GetDataSet("select * from T_IN_PATIENT a  inner join t_inhospital_action b on a.id=b.pid where a.patient_name<>'" + txtName + "' and a.pid='" + id + "' and b.action_type<>'出区'");
        if (ds != null)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }

    /// <summary>
    /// 获取天数
    /// </summary>
    private int GetDay(int month, int year)
    {

        int day = 0;
        switch (month)
        {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                day = 31;
                break;
            case 2:
                //闰年天，平年天
                if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
                {
                    day = 29;
                }
                else
                {
                    day = 28;
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                day = 30;
                break;
        }
        return day;

    }



}